<template>
  <a-card :bordered="false">
    <a-tabs default-active-key="1" @change="tabChange">
      <a-tab-pane key="1" tab="封号列表">
      </a-tab-pane>
      <a-tab-pane key="2" tab="禁言列表">
      </a-tab-pane>
    </a-tabs>
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
        <a-col :xl="6" :lg="7" :md="8" :sm="24" v-if="queryParam.type=='1'">
          <a-form-item label="封号状态">
            <a-select placeholder="请选择" v-model="queryParam.banStatus">
              <a-select-option value="1">封号中</a-select-option>
              <a-select-option value="2">已解封</a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
        <a-col :xl="6" :lg="7" :md="8" :sm="24" v-else>
          <a-form-item label="禁言状态">
            <a-select placeholder="请选择" v-model="queryParam.banStatus">
              <a-select-option value="5">禁言中</a-select-option>
              <a-select-option value="6">禁提现中</a-select-option>
              <a-select-option value="7">已解除禁言</a-select-option>
            </a-select>
          </a-form-item>
        </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="ID">
              <a-input placeholder="请输入" v-model="queryParam.userId"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="昵称">
              <a-input placeholder="请输入" v-model="queryParam.userName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">

    </div>

    <!-- table区域-begin -->
    <div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="unseal(record.id)" v-if="record.banStatus=='1'">解封</a>
          <a @click="removeBanIm(record.id)" v-if="record.banStatus=='5' || record.banStatus=='6'">解除禁言</a>
          <a-divider type="vertical" v-if="record.banStatus=='5'"/>
          <a @click="removeImCall(record.id)" v-if="record.banStatus=='5'">解除聊天限制</a>
        </span>

      </a-table>
    </div>

    <banaccount-modal ref="modalForm" @ok="modalFormOk"></banaccount-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import BanaccountModal from './modules/BanaccountModal'
  import { getAction } from '@/api/manage'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'

  export default {
    name: 'BanaccountList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      BanaccountModal
    },
    data () {
      return {
        description: '封禁、禁言账号表管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'ID',
            align:"center",
            dataIndex: 'userId'
          },
          {
            title:'昵称',
            align:"center",
            dataIndex: 'userName'
          },
          {
            title:'性别',
            align:"center",
            dataIndex: 'sex_dictText'
          },
          {
            title:'手机号码',
            align:"center",
            dataIndex: 'phone'
          },
          {
            title:'封号原因',
            align:"center",
            dataIndex: 'banReason'
          },
          {
            title:'证明',
            align:"center",
            dataIndex: 'fileUrl',
            scopedSlots: {customRender: 'fileSlot'}
          },
          {
            title:'封号状态',
            align:"center",
            dataIndex: 'banStatus_dictText'
          },
          {
            title:'封号开始时间',
            align:"center",
            dataIndex: 'beginTime'
          },
          {
            title:'封号结束时间',
            align:"center",
            dataIndex: 'endTime'
          },
          {
            title:'操作人名称',
            align:"center",
            dataIndex: 'createName'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/user/banaccount/list",
          delete: "/user/banaccount/delete",
          deleteBatch: "/user/banaccount/deleteBatch",
          exportXlsUrl: "/user/banaccount/exportXls",
          importExcelUrl: "user/banaccount/importExcel",

        },
        dictOptions:{},
        superFieldList:[],
        disableMixinCreated:true,
      }
    },
    created() {
      this.queryParam.type='1';
      this.loadData(1);
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      //tab切换
      tabChange(val){
        this.queryParam.type=val;
        this.loadData(1);
      },
      //重置
      searchReset() {
        var type=this.queryParam.type;
        this.queryParam = {type:type},
        this.loadData(1);
      },
      //解除封号
      unseal(id){
        this.loading = true
        getAction("/user/banaccount/unseal", {id:id}).then(res => {
          if (res.success) {
            this.$message.success(res.message);
            this.loadData();
          } else {
            this.$message.warn(res.message)
          }
        }).finally(() => {
          this.loading = false
        })
      },

      //解除聊天限制
      removeImCall(id){
        this.loading = true
        getAction("/user/banaccount/removeImCall", {id:id}).then(res => {
          if (res.success) {
            this.$message.success(res.message);
            this.loadData();
          } else {
            this.$message.warn(res.message)
          }
        }).finally(() => {
          this.loading = false
        })
      },

      //解除禁言
      removeBanIm(id){
        this.loading = true
        getAction("/user/banaccount/removeBanIm", {id:id}).then(res => {
          if (res.success) {
            this.loadData();
            this.$message.success(res.message)
          } else {
            this.$message.warn(res.message)
          }
        }).finally(() => {
          this.loading = false
        })
      }

    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>